package org.invigorare.auctions.widgets;

import org.invigorare.auctions.R;
import org.invigorare.auctions.data.entities.Licensee;
import org.invigorare.auctions.data.entities.Licensee.LicenseType;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

public class LicenseeDisplayHelper {

	public static void setLicenseeToDisplay(Context context, View v, Licensee lic, Licensee.LicenseType licenseTypeToDisplay) {
		
		boolean addrExists = true;
		if (lic == null) {
			lic = new Licensee("", "", "", "", "", "", "");
			addrExists = false;
		}
		
    	TextView name = (TextView) v.findViewById(R.id.licensee_name);
    	TextView addr = (TextView) v.findViewById(R.id.licensee_addr);
    	TextView licNo = (TextView) v.findViewById(R.id.licensee_lic);
    	TextView org = (TextView) v.findViewById(R.id.licensee_org);

    	if (name != null) {
    		name.setText(lic.name);
    	}
    	
    	if (addr != null) {
    		if (addrExists) {
	    		addr.setText(context.getString(
	    				R.string.licensee_list_item_addr_format,
	    				lic.addr_street,
	    				lic.addr_state,
	    				lic.addr_pin));
    		} else {
    			addr.setText("");
    		}
    	}
    	
    	if (licNo != null) {
    		String toDisp = "[NO LIC]";
    		if (licenseTypeToDisplay == LicenseType.SELLER_LICENSE) {
    			toDisp = lic.seller_lic;
    		} else if (licenseTypeToDisplay == LicenseType.BUYER_LICENSE) { 
    			toDisp = lic.buyer_lic;
    		}
    		licNo.setText(context.getString(
    				R.string.licensee_list_item_licNo_format,
    				toDisp));
    	}
    	
    	if (org != null) {
    		org.setText(lic.organization);
    	}
	}

}
